var index;
//获取商品Id
var id = $("#goodsIdd").val();
$(function(){

	var colorO = '';
	var chicun = '';
	var val3 =0;
	var val2 = 0;
	//选择颜色尺码规格分类
	$('.goodDataT').click(function(){
		$('body').css({overflow:'hidden'});
		$('html').css({overflow:'hidden'});
		$('.attribute').css({display:'block'});
		$('.meng').css({display:'block'});
		$('.goodDataB').css({display:'none'});
		//关闭规格确定弹窗
		$('.attributes>img').click(function(){
			$('body').css({overflow:'visible'});
			$('html').css({overflow:'visible'});
			$('.attribute').css({display:'none'});
			$('.meng').css({display:'none'});
			$('.goodDataB').css({display:'block'});
		});
		$('.addAs').click(function(){
			
			 if($('.goodesT a').length > 0 && $('.goodesF a').length > 0 ){
				 if($('.goodesF a i').text()=='已选中'&&$('.goodesT a i').text()=='已选中'){				 	
						$('.attribute').css({display:'none'});
						$('.meng').css({display:'none'});
						$('.goodDataB').css({display:'block'});
						$('.goodDataT span  i:nth-child(1)').text('已选：'+colorO);
						$('.goodDataT span  i:nth-child(1)').css({marginRight:'2.0rem'})
						$('.goodDataT span  i:nth-child(2)').text(chicun);
						$('body').css({overflow:'visible'});
						$('html').css({overflow:'visible'});
				 }	
			 	 if($(".goodesT").children(".selected").length > 0 && $(".goodesF").children(".selected").length == 0){
			 		alert("请选择商品"+ $(".goodesF").prev().text() +"!");
			 		return false;
			 	 }else if ($(".goodesF").children(".selected").length > 0 && $(".goodesT").children(".selected").length == 0){
			 		alert("请选择商品"+ $(".goodesT").prev().text() +"!");
			 		return false;
			 	 }else if($(".goodesF").children(".selected").length == 0  && $(".goodesT").children(".selected").length == 0){
			 		 alert("请选择商品规格!");
			 		 return false;
			 	 }	    				
		    }else if($('.goodesT a').length > 0 && $('.goodesF a').length == 0 ){
		    	 if($('.goodesT a i').text()=='已选中'){				 	
						$('.attribute').css({display:'none'});
						$('.meng').css({display:'none'});
						$('.goodDataB').css({display:'block'});
						$('.goodDataT span  i:nth-child(1)').text('已选：'+colorO);
						$('.goodDataT span  i:nth-child(1)').css({marginRight:'2.0rem'})
						$('.goodDataT span  i:nth-child(2)').text(chicun);
						$('body').css({overflow:'visible'});
						$('html').css({overflow:'visible'});
				 }	
			 	 if($(".goodesT").children(".selected").length  == 0){
			 		alert("请选择商品"+ $(".goodesT").prev().text() +"!");
			 		return false;
			 	 }    				
		    }else if($('.goodesT a').length == 0 && $('.goodesF a').length > 0 ){
		    	 if($('.goodesF a i').text()=='已选中'){				 	
						$('.attribute').css({display:'none'});
						$('.meng').css({display:'none'});
						$('.goodDataB').css({display:'block'});
						$('.goodDataT span  i:nth-child(1)').text('已选：'+colorO);
						$('.goodDataT span  i:nth-child(1)').css({marginRight:'2.0rem'})
						$('.goodDataT span  i:nth-child(2)').text(chicun);
						$('body').css({overflow:'visible'});
						$('html').css({overflow:'visible'});
				 }	
			 	 if( $(".goodesF").children(".selected").length == 0){
			 		alert("请选择商品"+ $(".goodesF").prev().text() +"!");
			 		return false;
		         }    				
		
	 	   }
			
			$('body').css({overflow:'visible'});
			$('html').css({overflow:'visible'});
			$('.attribute').css({display:'none'});
			$('.meng').css({display:'none'});
			$('.goodDataB').css({display:'block'});
		});
		
	});
	//选择规格
	$('.goodesT a').click(function(){
		
		for (var i = 0; i<$('.goodesT a').length;i++) {
			index = $('.goodesT a').index(this);
		}
		colorO = $(this).text();
		$('.goodesT a i').text('');
		$('.goodesT a').css({border:'1px solid rgb(102,102,102)',color:'rgb(51,51,51)'});
		$(this).css({border:'1px solid rgb(202,14,84)',color:'rgb(202,14,84)'});
		$(this).addClass('selected','selected');
		$(this).siblings().removeClass('selected');
		$('.goodesT a i').eq(index).text('已选中');
		$('.goodesT a i').eq(index).css({fontSize:'0.0000001rem',opacity:'0',position:'absolute',left:'0'});
		
		//根据选择的规格计算对应的商品库存
	//	var $color =$(this).text().replace("已选中","");
		var $color = colorO.replace("已选中","");
		var $size = $('.goodesF > .selected');
		$size  = $size && $size.length >0 ? $size.text().replace("已选中",""):"";	    
		
		var $colori = $('.goodesT').prev();
		$colori = $colori && $colori.length >0 ? $colori.text().replace("已选中",""):"";	

		var $sizei = $('.goodesF').prev();
		$sizei = $sizei && $sizei.length >0 ? $sizei.text().replace("已选中",""):"";
		
		var skuInfo = $colori + ":" + $color +","+ $sizei+":" + $size;	
		
		var stock = getGoodsStock(skuInfo);
		var $input = $('.addA div input');
		var $mount = parseInt($input.val());
		if($mount > stock){
			alert("商品数量超库存了!");
	    	$input.val(stock);
	    }
		if($mount == 0){
			$input.val(1);
		}
	    $(".attributes p span:nth-child(3) > .productStock").text(stock);
	    
	});
	
	//记录用户选择的颜色尺码规格
	function goodsDataT(){
		   $('.addAs').click(function(){
				if($('.goodesF a i').text()=='已选中'&&$('.goodesT a i').text()=='已选中'){				 	
					$('.attribute').css({display:'none'});
					$('.meng').css({display:'none'});
					$('.goodDataB').css({display:'block'});
					$('.goodDataT span  i:nth-child(1)').text('已选：'+colorO);
					$('.goodDataT span  i:nth-child(1)').css({marginRight:'2.0rem'})
					$('.goodDataT span  i:nth-child(2)').text(chicun);
					$('body').css({overflow:'visible'});
					$('html').css({overflow:'visible'});
				}else{
					$('.attribute').css({display:'block'});
					$('.meng').css({display:'block'});
					$('body').css({overflow:'hidden'});
					$('html').css({overflow:'hidden'});
					$('.goodDataB').css({display:'none'});
				}
		   });
	}
	//选择规格
	$('.goodesF a').click(function(){
		chicun = $(this).text();
		$('.goodesF a i').text('')
		for (var i = 0; i<$('.goodesF a').length;i++) {
			index = $('.goodesF a').index(this);
		}
		$('.goodesF a').css({border:'1px solid rgb(102,102,102)',color:'rgb(51,51,51)'});
		$(this).css({border:'1px solid rgb(202,14,84)',color:'rgb(202,14,84)'});
		$(this).addClass('selected','selected');
		$(this).siblings().removeClass('selected');
		$('.goodesF a i').eq(index).text('已选中');
		$('.goodesF a i').eq(index).css({fontSize:'0.0000001rem',opacity:'0',position:'absolute',left:'0'});
		
		//根据选择的规格计算对应的商品库存
		var $size =chicun.replace("已选中","");
		var $color = $('.goodesT .selected');
		$color  = $color && $color.length >0 ? $color.text().replace("已选中",""):"";	    
		
		var $sizei = $('.goodesF').prev();	
		$sizei = $sizei && $sizei.length >0 ? $sizei.text().replace("已选中",""):"";

		var $colori =  $('.goodesT').prev();
		$colori = $colori && $colori.length >0 ? $colori.text().replace("已选中",""):"";
		
		var skuInfo = $colori + ":" + $color +","+ $sizei+":" + $size;
		
		var stock = getGoodsStock(skuInfo);
		var $input = $('.addA div input');
		var $mount = parseInt($input.val());
		if($mount > stock){
			alert("商品数量超库存了!");
	    	$input.val(stock);
	    }
		if($mount == 0){
			$input.val(1);
		}
	    $(".attributes p span:nth-child(3) > .productStock").text(stock);
	    goodsDataT();
	});

	//加减
	$('.jia').click(function(){
		for (var i=0;i<$('.jia').length;i++) {
			index=$('.jia').index(this);
		}
		nu = $('.addA input').eq(index).val();
		nu++;
		$('.addA input').eq(index).val(nu);
		val3 = $('.addA input').eq(index).val();
	});
	$('.scnImg').click(function(){
		for (var i=0;i<$('.scnImg').length;i++) {
			index=$('.scnImg').index(this);
		}
		nu = $('.addA input').eq(index).val();
		if(nu>1){
			nu--;
		$('.addA input').eq(index).val(nu);
		val3 = $('.addA input').eq(index).val();
	     
		}

	});
	function showAddAsDiv(){
		$('.attribute').css({
			display : 'block'
		});
		$('.meng').css({
			display : 'block'
		});
		$('body').css({
			overflow : 'hidden'
		});
		$('html').css({
			overflow : 'hidden'
		});
		$('.goodDataB').css({
			display : 'none'
		});
	}
	function hideAddAsDiv(){
		$('.attribute').css({
			display : 'none'
		});
		$('.meng').css({
			display : 'none'
		});
		$('.goodDataB').css({
			display : 'block'
		});
		$('.goodDataT span  i:nth-child(1)').text('已选：' + colorO);
		$('.goodDataT span  i:nth-child(1)').css({
			marginRight : '2.0rem'
		})
		$('.goodDataT span  i:nth-child(2)').text(chicun);
		$('body').css({
			overflow : 'visible'
		});
		$('html').css({
			overflow : 'visible'
		});
	}	
	
	//商品月销数量
	monthSaleMount();
	
	//获取商品库存
	updateGoodsStock();
	
	//监听商品数量不能超过库存
	$('.addA div input').change(function(){
	    var $stock =  $(".attributes p span:nth-child(3) > .productStock").text();
	    $stock = parseInt($stock);
	    if($(this).val() > $stock){
			alert("商品数量超库存了!");
	    	$(this).val($stock);
	    }
	    var $input = $('.addA div input');
		var $mount = parseInt($input.val());
		if($mount > $stock){
			alert("商品数量超库存了!");
	    	$input.val(stock);
	    }
	  if($(this).val() < 1 || !$(this).val() || isNaN($(this).val()) || $(this).val()=="" || $mount == 0){
    		$(this).val(1);
    	}
	});
   //查看店铺
	$('.foot li:nth-child(1)').click(function(){
		//location.href='store.html'
			location.href='#'
	});
	//查看购物车
	$('.foot li:nth-child(2)').click(function(){
		location.href=rootPath + '/cart/getCart';
	});
    //收藏
	$('.foot li:nth-child(3)').click(function(){
		index++;
		if(index%2!=0){
			$('.foot li:nth-child(3) img').attr('src',rootPath + '/image/sc-y.png');
			$('.foot li:nth-child(3) img').css({width: '5.3rem',height: "4.6rem"})
			$('.foot li:nth-child(3) span').text('已收藏');
			addOrCacelFavorites("1"); //商品是否已被收藏（0：否，1：是）
		}else{
			$('.foot li:nth-child(3) img').attr('src',rootPath + '/image/sc.png');
			$('.foot li:nth-child(3) span').text('收藏');
			addOrCacelFavorites("0"); //商品是否已被收藏（0：否，1：是）
		}
	});
	//加入购物车
	var addCartFlag = false;
	$('.foot li:nth-child(4)').click(function(){
		addCartFlag = true;
		//关闭规格确定弹窗
		$('.attributes>img').click(function(){
			$('body').css({overflow:'visible'});
			$('html').css({overflow:'visible'});
			$('.attribute').css({display:'none'});
			$('.meng').css({display:'none'});
			$('.goodDataB').css({display:'block'});
			addCartFlag = false;
		});
		//判断用户是否登录
	    if(member == null){
	    	window.location.href=rootPath + '/member/loginPre?redirect=/goods/queryGoodsDetail?id='+id;
	    	return false;
	    }
		if($('.goodDataT span  i:nth-child(1)').text()=='选择颜色，'){
			$('.attribute').css({display:'block'});
			$('.meng').css({display:'block'});
			$('body').css({overflow:'hidden'});
			$('html').css({overflow:'hidden'});
			$('.goodDataB').css({display:'none'});
			//return;
		}else{
			goCart();
		}
		$('.addAs').click(function(){
			showAddAsDiv();
			if(addCartFlag){				
	   		 	 if( parseInt($(".attributes p span:nth-child(3) > .productStock").text()) == 0){
	 		 		alert("此宝贝已售完,请重新选择!");
	 		 		return false;
	 		 	 }
				if($('.goodesF a i').text()=='已选中'&&$('.goodesT a i').text()=='已选中'){				 	
					$('.attribute').css({display:'none'});
					$('.meng').css({display:'none'});
					$('.goodDataB').css({display:'block'});
					$('.goodDataT span  i:nth-child(1)').text('已选：'+colorO);
					$('.goodDataT span  i:nth-child(1)').css({marginRight:'2.0rem'})
					$('.goodDataT span  i:nth-child(2)').text(chicun);
					$('body').css({overflow:'visible'});
					$('html').css({overflow:'visible'});
					goCart();
				}else{
				   if($('.goodesT a').length > 0 && $('.goodesF a').length > 0 ){
							
					 	 if($(".goodesT").children(".selected").length > 0 && $(".goodesF").children(".selected").length == 0){
					 		alert("请选择商品"+ $(".goodesF").prev().text() +"!");
					 		return false;
					 	 }else if ($(".goodesF").children(".selected").length > 0 && $(".goodesT").children(".selected").length == 0){
					 		alert("请选择商品"+ $(".goodesT").prev().text() +"!");
					 		return false;
					 	 }else if($(".goodesF").children(".selected").length == 0  && $(".goodesT").children(".selected").length == 0){
					 		 alert("请选择商品规格!");
					 		 return false;
					 	 }	    				
				   }else if($('.goodesT a').length > 0 && $('.goodesF a').length == 0 ){
						
					 	 if($(".goodesT").children(".selected").length  == 0){
					 		alert("请选择商品"+ $(".goodesT").prev().text() +"!");
					 		return false;
					 	 }    				
				   }else if($('.goodesT a').length == 0 && $('.goodesF a').length > 0 ){
						
					 	 if( $(".goodesF").children(".selected").length == 0){
					 		alert("请选择商品"+ $(".goodesF").prev().text() +"!");
					 		return false;
				         }    				
				
			 	   }
				   goCart();
		      }
			}
		});
	});
	//立即购买
	var goBuyFlag = false;
	$('.foot li:nth-child(5)').click(function(){
		goBuyFlag= true;
        //关闭规格确定弹窗
		$('.attributes>img').click(function(){
			$('body').css({overflow:'visible'});
			$('html').css({overflow:'visible'});
			$('.attribute').css({display:'none'});
			$('.meng').css({display:'none'});
			$('.goodDataB').css({display:'block'});
			goBuyFlag = false;
		});
		//判断用户是否登录
	    if(member == null){
	    	window.location.href=rootPath + '/member/loginPre?redirect=/goods/queryGoodsDetail?id='+id;
	    	return false;
	    }
		if($('.goodDataT span  i:nth-child(1)').text()=='选择颜色，'){
			$('.attribute').css({display:'block'});
			$('.meng').css({display:'block'});
			$('body').css({overflow:'hidden'});
			$('html').css({overflow:'hidden'});
			$('.goodDataB').css({display:'none'});
		
		}else{
		//	location.href='order.html';
			goBuy();
		}
		$('.addAs').click(function(){
			showAddAsDiv();
			if(goBuyFlag){
			 	if( parseInt($(".attributes p span:nth-child(3) > .productStock").text()) == 0){
			 		alert("此宝贝已售完,请重新选择!");
			 		return false;
			 	}
				if($('.goodesF a i').text()=='已选中'&&$('.goodesT a i').text()=='已选中'){
					$('.attribute').css({display:'none'});
					$('.meng').css({display:'none'});
					$('.goodDataB').css({display:'block'});
					$('.goodDataT span  i:nth-child(1)').text('已选：'+colorO);
					$('.goodDataT span  i:nth-child(1)').css({marginRight:'2.0rem'})
					$('.goodDataT span  i:nth-child(2)').text(chicun);
					$('body').css({overflow:'visible'});
					$('html').css({overflow:'visible'});
					goBuy();
				}else{	
					  if($('.goodesT a').length > 0 && $('.goodesF a').length > 0 ){
							
						 	 if($(".goodesT").children(".selected").length > 0 && $(".goodesF").children(".selected").length == 0){
						 		alert("请选择商品"+ $(".goodesF").prev().text() +"!");
						 		return false;
						 	 }else if ($(".goodesF").children(".selected").length > 0 && $(".goodesT").children(".selected").length == 0){
						 		alert("请选择商品"+ $(".goodesT").prev().text() +"!");
						 		return false;
						 	 }else if($(".goodesF").children(".selected").length == 0  && $(".goodesT").children(".selected").length == 0){
						 		 alert("请选择商品规格!");
						 		 return false;
						 	 }	    				
					   }else if($('.goodesT a').length > 0 && $('.goodesF a').length == 0 ){
							
						 	 if($(".goodesT").children(".selected").length  == 0){
						 		alert("请选择商品"+ $(".goodesT").prev().text() +"!");
						 		return false;
						 	 }    				
					   }else if($('.goodesT a').length == 0 && $('.goodesF a').length > 0 ){
							
						 	 if( $(".goodesF").children(".selected").length == 0){
						 		alert("请选择商品"+ $(".goodesF").prev().text() +"!");
						 		return false;
						 	 }    				
					
					  }	
					  goBuy();
		      }
			}
			
		});
	});
});

/**
 * @title 添加或取消收藏
 * @param selected 商品是否已被收藏（0：否，1：是） 
 */
function addOrCacelFavorites(selected){
	//获取商品Id 
	var id = $("#goodsIdd").val();
	//判断用户是否登录
    if(member == null){
    	window.location.href=rootPath + '/member/loginPre?redirect=/goods/queryGoodsDetail?id='+id;
    	return false;
    }
    var url = rootPath + "/cart/addOrCacelFavorites";
	var data={};
	data["goodsId"] = id;
	data["selected"]=selected;
	data["sellerId"] ="1"; //默认企商云一个店铺
	data["collectionType"] =  "1";  //收藏类型 1：商品，2：店铺 
	var result = CommnUtil.ajax(url,data,"json");
	if(result.resultSuccess){
		if(selected == '0'){
			alert("取消收藏成功!",{icon:1,skin: 'layui-layer-red ',offset: ['40%', '45%']});
		}else if(selected ='1'){
			alert("收藏成功!",{icon:1,skin: 'layui-layer-red ',offset: ['40%', '45%']});
		}
		
	}else if(result.sessionValid){
    	window.location.href=rootPath + '/member/loginPre?redirect=/goods/queryGoodsDetail?id='+id;
    	return false;
	}else  if(result.resultSuccess == false){
		alert(result.resultDesc);
    	return false;
	}
}

//根据选中的规格参数计算商品的库存值
function updateGoodsStock(){
	var stock = getGoodsStock("");
	var $input = $(".addA div input");
	var $span = $('.attributes p span:nth-child(3) > .productStock');
	var $mount = parseInt($input.val());
	if($mount > stock){
		alert("商品数量超库存了!");
		$input.val(stock);
    }
	$span.text(stock);
	
}
//获取商品库存
function getGoodsStock(skuInfo){
	var url = rootPath + "/cart/getGoodsStockBySkuValues";
	var data={};
	data["productId"] =$("#goodsIdd").val();
	data['goods_sku_info']=skuInfo?skuInfo:"";
	var url = rootPath + '/cart/getGoodsStockBySkuValues';
	var result = CommnUtil.ajax(url, data, "json");	
	if(result.resultSuccess){
		//alert("商品库存：" + result.stock)
		return result.stock;
	}else{
		alert("商品库存读取失败!");	
	}
	return 0;
}
//商品月销数量(有效的订单中商品的数量，包含被删除的)
function monthSaleMount(){
	var url = rootPath + "/goods/selectGoodsMonthSaleMount";
	var data={"goodsId":$("#goodsIdd").val()};
	var result = CommnUtil.ajax(url, data, "json");	
	if(result.resultSuccess){
	 	 //alert( $(".goodDataO div p .monthSale").text());
		 $(".goodDataO div p .monthSale").text(result.monthSaleMount);
	}else{
		alert("商品月销数量读取失败!");	
	}
}

//立即购买商品	
function goBuy(){
	//判断用户是否登录
    if(member == null){
  	   window.location.href=rootPath + '/member/loginPre?redirect=/goods/queryGoodsDetail?id='+id;
	   return false;
    }        
	if( parseInt($(".attributes p span:nth-child(3) > .productStock").text()) == 0){
		alert("该规格商品已售完,请重新选择!");
		return false;
	}
    if($('.goodesT a').length > 0 && $('.goodesF a').length > 0 ){
		
	 	 if($(".goodesT").children(".selected").length > 0 && $(".goodesF").children(".selected").length == 0){
	 		alert("请选择商品"+ $(".goodesF").prev().text() +"!");
	 		return false;
	 	 }else if ($(".goodesF").children(".selected").length > 0 && $(".goodesT").children(".selected").length == 0){
	 		alert("请选择商品"+ $(".goodesT").prev().text() +"!");
	 		return false;
	 	 }else if($(".goodesF").children(".selected").length == 0  && $(".goodesT").children(".selected").length == 0){
	 		 alert("请选择商品规格!");
	 		 return false;
	 	 }	    				
     }else if($('.goodesT a').length > 0 && $('.goodesF a').length == 0 ){
		
	 	 if($(".goodesT").children(".selected").length  == 0){
	 		alert("请选择商品"+ $(".goodesT").prev().text() +"!");
	 		return false;
	 	 }    				
     }else if($('.goodesT a').length == 0 && $('.goodesF a').length > 0 ){
		
	 	 if( $(".goodesF").children(".selected").length == 0){
	 		alert("请选择商品"+ $(".goodesF").prev().text() +"!");
	 		return false;
	 	 }    				
     }
	//遍历获取div的内容
	var colorAndSize="";
	var goodsSkuValueIds = "";
	$(".addAttributes > li").children(".selected").each(function(){
		var cs = $(this).parent().prev().text()+":" +$(this).text().replace("已选中","");
		var goodsSkuValueId = $(this).attr("goodsSkuValueId");
		colorAndSize += cs+",";
		goodsSkuValueIds += goodsSkuValueId +",";
	 }); 
	var url = rootPath + "/order/goBuy";
	var data={};
	data["goodsId"] = id;
	data["goods_sku_id"]=goodsSkuValueIds;
	data["goods_sku_info"] =colorAndSize;
	data["mount"] =$('.addA div input').val();
	//alert($("#divTest .number input").val());
	var result = CommnUtil.ajax(url,data,"json");
	//alert("立即购买.........商品ID:"+id+"===商品规格:"+colorAndSize)
	if(result.resultSuccess){
		//alert("加入购物车成功!");
		var $url = rootPath + '/order/order?type=1&goodsId='+id;		
		window.open($url,'_self'); 
	}else if(result.sessionValid){
	  	window.location.href=rootPath + '/member/loginPre?redirect=/goods/queryGoodsDetail?id='+id;
		return false;
	}else if(result.resultSuccess == false){
		alert(result.resultDesc);
    	return false;
	}
}	
//加入购物车
function goCart(){
	//获取商品Id
	var id = $("#goodsIdd").val();
	//判断用户是否登录
  if(member == null){
  	window.location.href=rootPath + '/member/loginPre?redirect=/goods/queryGoodsDetail?id='+id;
  	return false;
   }

	if( parseInt($(".attributes p span:nth-child(3) > .productStock").text()) == 0){
		alert("该规格商品已售完,请重新选择!");
		return false;
	}

	  if($('.goodesT a').length > 0 && $('.goodesF a').length > 0 ){
			
		 	 if($(".goodesT").children(".selected").length > 0 && $(".goodesF").children(".selected").length == 0){
		 		alert("请选择商品"+ $(".goodesF").prev().text() +"!");
		 		return false;
		 	 }else if ($(".goodesF").children(".selected").length > 0 && $(".goodesT").children(".selected").length == 0){
		 		alert("请选择商品"+ $(".goodesT").prev().text() +"!");
		 		return false;
		 	 }else if($(".goodesF").children(".selected").length == 0  && $(".goodesT").children(".selected").length == 0){
		 		 alert("请选择商品规格!");
		 		 return false;
		 	 }	    				
	   }else if($('.goodesT a').length > 0 && $('.goodesF a').length == 0 ){
			
		 	 if($(".goodesT").children(".selected").length  == 0){
		 		alert("请选择商品"+ $(".goodesT").prev().text() +"!");
		 		return false;
		 	 }    				
	   }else if($('.goodesT a').length == 0 && $('.goodesF a').length > 0 ){
			
		 	 if( $(".goodesF").children(".selected").length == 0){
		 		alert("请选择商品"+ $(".goodesF").prev().text() +"!");
		 		return false;
		 	 }    				
	   }
	//遍历获取div的内容
	var colorAndSize="";
	var goodsSkuValueIds = "";
	$(".addAttributes > li").children(".selected").each(function(){
		var cs = $(this).parent().prev().text()+":" +$(this).text().replace("已选中","");
		var goodsSkuValueId = $(this).attr("goodsSkuValueId");
		colorAndSize += cs+",";
		goodsSkuValueIds += goodsSkuValueId +",";
	 });
	var url = rootPath + "/cart/addProduct";
	var data={};
	data["productId"] = id;
	data["goods_sku_id"]=goodsSkuValueIds;
	data["goods_sku_info"] =colorAndSize;
	data["memberId"] = member.mId;
	data["mount"] =$('.addA div input').val();
	//alert($("#divTest .number input").val());
	var result = CommnUtil.ajax(url,data,"json");
	//alert("立即购买.........商品ID:"+id+"===商品规格:"+colorAndSize)
	if(result.resultSuccess){
		alert("加入购物车成功!");
		window.location.reload();
	}else if(result.sessionValid){
     	window.location.href=rootPath + '/member/loginPre?redirect=/goods/queryGoodsDetail?id='+id;
	    return false;
	}else if(result.resultSuccess == false){
		alert(result.resultDesc);
		return false;
	}
}
